package edu.scau.cxq.gp.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import edu.scau.cxq.gp.entity.SystemNotice;
import edu.scau.cxq.gp.entity.vo.NoticeVO;
import edu.scau.cxq.gp.entity.vo.UserVO;
import edu.scau.cxq.gp.mapper.SystemNoticeMapper;
import edu.scau.cxq.gp.service.SystemNoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SystemNoticeServiceImpl implements SystemNoticeService {

    @Resource
    private SystemNoticeMapper systemNoticeMapper;

    @Override
    public PageInfo<SystemNotice> getNoticeList(Integer currentPage, Integer size, NoticeVO noticeVO) {
        PageHelper.startPage(currentPage, size);
        List<SystemNotice> systemNotices = systemNoticeMapper.selectNoticeList(noticeVO);
        PageInfo<SystemNotice> systemNoticePageInfo = new PageInfo<>(systemNotices);
        return systemNoticePageInfo;
    }
    @Override
    public List<SystemNotice> getSystemNoticeList() {
        return systemNoticeMapper.selectList(null);
    }

    @Override
    public SystemNotice getSystemNoticeById(int id) {
        return systemNoticeMapper.selectNoticeStatus(id);
    }

    @Override
    public boolean createSystemNotice(SystemNotice systemNotice) {
        return systemNoticeMapper.insert(systemNotice) > 0;
    }

    @Override
    public boolean updateSystemNotice(SystemNotice systemNotice) {
        return systemNoticeMapper.updateById(systemNotice) > 0;
    }

    @Override
    public boolean deleteSystemNotice(int id) {
        return systemNoticeMapper.deleteById(id) > 0;
    }

    @Override
    public SystemNotice getNotice(int id) {
        return systemNoticeMapper.selectById(id);
    }
}
